package sp.whereru;

/**
 * Class for holding a simple time with only hours and minutes
 * @author Josh Tate
 *
 */
public class SimpleTime {
	private int hours;
	private int minutes;
	private int totalTime;
	
	/**
	 * Constructs a new SimpleTime object given no parameters
	 */
	public SimpleTime() {
		hours = 0;
		minutes = 0;
		totalTime = 0;
	}
	
	/**
	 * Constructs a new SimpleTime object given the hours and minutes
	 * @param hours		the number of hours
	 * @param minutes	the number of minutes
	 */
	public SimpleTime(int hours, int minutes) {
		this.hours = hours;
		this.minutes = minutes;
		calculateTotalTime();
	}
	
	/**
	 * Constructs a new SimpleTime object given the total time in minutes
	 * @param totalTime the total time in minutes
	 */
	public SimpleTime(int totalTime) {
		this.hours = totalTime / 60;
		this.minutes = totalTime % 60;
		this.totalTime = totalTime;
	}
	
	/**
	 * Calculates the total time in minutes
	 */
	public void calculateTotalTime() {
		totalTime = (hours * 60) + minutes;
	}
	
	/**
	 * Converts the current time to format 00:00AM
	 * @return the string value represented the time
	 */
	public String toString() {
		String am_pm = "am";
		int mHour = hours;
		if(mHour > 11) {
			am_pm = "pm";
			if(mHour > 12)
				mHour -= 12;
		}
		else if(mHour == 0)
			mHour += 12;

		String mMinute = String.valueOf(minutes);
		if(minutes < 10)
			mMinute = "0" + mMinute;
			
		return (mHour + ":" + mMinute + am_pm);
	}
	
	public int getHours() 		{ return hours;		}
	public int getMinutes() 	{ return minutes;	}
	public int getTotalTime() 	{ return totalTime;	}
	
	public void setHours(int hours) 		{ this.hours = hours;			}
	public void setMinutes(int minutes) 	{ this.minutes = minutes;		}
	public void setTotalTime(int totalTime) { this.totalTime = totalTime;	}

	
	
}
